import js from '@eslint/js';
import { defineConfig } from 'eslint/config';
import globals from 'globals';

import eslintPluginVue from 'eslint-plugin-vue';
import importPlugin from 'eslint-plugin-import';
import eslintPluginPrettier from 'eslint-plugin-prettier/recommended';

import tsEslint from 'typescript-eslint';

// --- Export ESLint configuration ---
export default defineConfig([
  { ignores: ['**/node_modules/**', '**/dist/**', '**/build/**'] },

  {
    files: ['**/*.{ts,vue}'],
    plugins: {
      import: importPlugin,
    },
    extends: [
      js.configs.recommended,
      ...tsEslint.configs.recommended,
      ...eslintPluginVue.configs['flat/recommended'],
    ],
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
      globals: {
        ...globals.browser,
        ...globals.node,
        uni: 'readonly',
      },
      parserOptions: {
        parser: tsEslint.parser,
      },
    },
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
    },
  },

  // 取消page层面 index 文件的检查
  {
    files: ['src/components/**/*.vue'], // ✅ 只对组件启用这条规则
    rules: {
      'vue/multi-word-component-names': 'error',
    },
  },
  {
    files: ['src/pages/**/*.vue'], // ✅ 页面不检查这条规则
    rules: {
      'vue/multi-word-component-names': 'off',
    },
  },

  eslintPluginPrettier,
]);
